---
description: "Generate OpenAPI (Swagger) definitions from your GraphQL API using Sofa. Endless possibilities. Use OpenAPI and useSofa from sofa-api to create the Swagger definitions out of your schema. Add the routes to OpenAPI and save the file to './swagger.json'. #GraphQL"
---

# OpenAPI (Swagger)

Thanks to GraphQL's Type System Sofa is able to generate OpenAPI (Swagger) definitions out of it. Possibilities are endless here. You get all the information you need in order to write your own definitions or create a plugin that follows any specification.

```ts
import { useSofa } from 'sofa-api';

useSofa({
  schema,
  basePath: '/api',
  openAPI: {
    info: {
      title: 'Example API',
      version: '3.0.0',
    },
    endpoint: '/openapi.json',
  },
  swaggerUI: {
    path: '/docs',
  }
})
```

> You can find swagger definitions in `/api/openapi.json` route.

## Extending OpenAPI

If you want to extend your OpenAPI document with [security schemes etc](https://swagger.io/docs/specification/v3_0/authentication/).
You can use `openAPI` option like below;

```ts
import { useSofa } from 'sofa-api';

useSofa({
  schema,
  basePath: '/api',
  openAPI: {
    info: {
      title: 'Example API',
      version: '3.0.0',
    },
    endpoint: '/openapi.json',
    servers: [{ url: 'https://my-production.com', description: 'Production' }],
    components: {
      securitySchemes: {
        bearerAuthorization: {
          type: 'http',
          scheme: 'bearer',
          bearerFormat: 'JWT',
          name: 'Authorization',
        },
      },
    },
  },
  swaggerUI: {
    path: '/docs',
  }
})
```
